package com.cy.store.service.impl;

import com.cy.store.entity.District;
import com.cy.store.mapper.DistrictMapper;
import com.cy.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DistrictServiceImpl implements IDistrictService {

    @Autowired
    DistrictMapper districtMapper;


    /**
     * 根据父地区（parent）查询数据
     */
    public List<District> getByParent(String Parent) {

        List<District> list = districtMapper.findByParent(Parent);


        // 去除多余数据
        for(District d: list){
            d.setId(null);
            d.setParent(null);
            System.err.println(d);
        }

        return list;
    }


    /**
     * 根据code查询数据
     */
    @Override
    public String getNameByCode(String code) {

        String name = districtMapper.findNameByCode(code);
        System.out.println("code = " + code + "，对应的名字是：" + name);

        return name;
    }
}
